<template>
  <div>
    <Chart :cdata="cdata" />
  </div>
</template>

<script>
import Chart from './chart.vue';
export default {
  props: {
    chartData: {
      type: Object,
      required: true
    }
  },
  data () {
    return {
      cdata: {
        name: ['新风', '排风', '控制器','空调'],
        data: [
          ['2015/11/08',0,'新风'],['2015/11/09',0,'新风'],['2015/11/10',0,'新风'],
          ['2015/11/11',0,'新风'],['2015/11/12',0,'新风'],['2015/11/13',0,'新风'],
          ['2015/11/14',0,'新风'],
          ['2015/11/08',0,'排风'],['2015/11/09',0,'排风'],['2015/11/10',0,'排风'],
          ['2015/11/11',0,'排风'],['2015/11/12',0,'排风'],['2015/11/13',0,'排风'],
          ['2015/11/14',0,'排风'],
          ['2015/11/08',0,'控制器'],['2015/11/09',0,'控制器'],['2015/11/10',0,'控制器'],
          ['2015/11/11',0,'控制器'],['2015/11/12',0,'控制器'],['2015/11/13',0,'控制器'],
          ['2015/11/14',0,'控制器'],
          ['2015/11/08',0,'空调'],['2015/11/09',0,'空调'],['2015/11/10',0,'空调'],
          ['2015/11/11',0,'空调'],['2015/11/12',0,'空调'],['2015/11/13',0,'空调'],
          ['2015/11/14',0,'空调']
        ],
      }
    }
  },
  components: {
    Chart,
  },
  mounted () {
  },
  methods: {
  },
  watch: {
    chartData: {
      handler({energy} ={}) {
        if(typeof(energy) === 'undefined' || typeof (energy.flowName) === 'undefined'){
          return
        }
        const flowNames = energy.flowName
        const data = []
        const flows = energy.flow
        for (const flow of flows){
          for(const flo of flow){
            data.push([flo.date,flo.flow,flo.name])
          }
        }
        this.cdata = {
          name : flowNames,
          data : data
        }
      },
      immediate: true,
      deep: true
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
